#include "GLWindow.h"

namespace mpgl_engine{ namespace application { namespace glfw {

	GLWindow::GLWindow()
		:Updateable()
	{
		m_glfWindow = NULL;
	}

	GLWindow::~GLWindow()
	{
		//Check if we need to set the window to close
		if ( m_glfWindow != NULL )
		{
			//Warning! This will completely destroy the window and
			// its context is detached if on the main thread, and
			// must not be on a separate thread.
			glfwDestroyWindow(m_glfWindow);
		}
	}

	bool GLWindow::CreateGLWindow(int width, int height, 
								const char *title, 
								GLFWmonitor *monitor, GLFWwindow *share)
	{
		//Check if the window already exists
		if (m_glfWindow)
			return false;
		//
		//glfwWindowHint(GLFW_REFRESH_RATE, 60);
		//Create window
		m_glfWindow =
			glfwCreateWindow(width, height, title, monitor, share);
		if (!m_glfWindow)
			return false;
		return true;
	}

	void GLWindow::MakeContextCurrent()
	{
		if ( m_glfWindow )
			glfwMakeContextCurrent(m_glfWindow);
		
	}

	void GLWindow::SwapBuffers()
	{
		glfwSwapBuffers(m_glfWindow);
	}
}}}